<?php

function basic($isadmin){
	require('config.php');
	print "<table border=\"0\">";
	
	
	# Look for some GET data, from the referrer page
	if (isset($_REQUEST["viewtype"])){ #Was any GET string tacked on to the URL?
		$view = $_REQUEST["viewtype"];
		$query = "select * from people where dept_id = $view ORDER BY lastname";
		} else {
		$query = "select * from people ORDER BY lastname";
		}
	
	# The "Show All" link: only if needed.
	if ($view == ""){
		$top_links = "";
		} else {
		$top_links = "<a href=\"http://backserv/coop-people/\">Show Everybody</a> ";
	}
	
	
	# IF this is an admin, show the "Add New" link with top links
	if($isadmin){
		$top_links += " <a href=\"#\">Add New</a>";
	}
	
	print $top_links; #TMP
	mysql_connect($hostname, $db_user, $db_pass) or die(mysql_error());
	mysql_select_db($db_name) or die(mysql_error());

	# Populate deptartment names array

	$dept_query = "select dept_name from depts";
	$dept_result = mysql_query($dept_query) or die(mysql_error());;
	$numdepts = mysql_num_rows($dept_result);
	$numdepts--;
	for ($i=0; $i<=$numdepts; $i++){ # For each of the depts, do...
	
		$dept_row = mysql_fetch_array($dept_result);
		
		$deptlist[$i] = $dept_row[0];	
		} # END dept names bit

	$result = mysql_query($query) or die(mysql_error());;
	$numrows=mysql_num_rows($result);

	$numrows--;
	for ($i=0; $i<=$numrows; $i++){ # For each of the rows, do...
		$row = mysql_fetch_array($result);
		# Assign variable values from query
		$idnum = $row[0];
		$firstname = $row[1];
		$lastname = $row[2];
		$title = $row[4];
		$dept = $row[5];
		if($isadmin){ # If this is for the admin view
			$del_link = "DEL LINK";
			$edit_link = "EDIT LINK";
			}
		# This bit makes rows of four
		if ($i % 4 ==0){
			$cell_top = "<tr><td>\n";
			$cell_bottom = "</td>\n";
			} else {
			$cell_top = "<td>\n";
			$cell_bottom = "</td>\n";
			}

		print $cell_top;
		print "<img src=\"$image_path/$idnum.jpg\" />";
		print "<br />";
		print "$firstname $lastname <br />$title <br /><a href=\"http://backserv/$local_dir?viewtype=$dept\">$deptlist[$dept]</a><p><br />";
		print $cell_bottom;
		print "<td width=\"20px\"></td>";	
		} #END of stuff for a given row
		print "</tr></table>";
		
	} #END of function basic()	

function adminview(){
		
	basic(TRUE); #Print the basic rows view WITH admin links
	}
	
function defaultview(){
	basic(FALSE); #Print the basic rows view WITHOUT admin links
	}
?>